<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>14_键盘事件-键码</title>
    </head>
    <body>
        <input type="text">

        <script>
            var inp = document.querySelector('input');

            inp.onkeyup = function(event){

                if(event.keyCode == 65) {
                    console.log('向左走');
                }else if(event.keyCode == 68){
                    console.log('向右走');
                }
            }
        </script>
    </body>
</html>